use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::IndicatorActionWrap;

/// Struct to hold the results of Klinger Volume Oscillator (KVO) calculations.
///
///  参见[KVO](https://docs.rs/yata/latest/yata/indicators/struct.KlingerVolumeOscillator.html)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct KVO {
    ///2 signals
    ///When main value crosses 0.0 upwards, then returns full buy signal.
    ///  When main value crosses 0.0 downwards, then returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,
    ///
    ///When main value crosses signal line value upwards, then returns full buy signal.
    /// When main value crosses signal line downwards, then returns full sell signal.
    /// Otherwise returns no signal.
    pub signal1: Option<IndicatorActionWrap>,

    /// 2 values
    /// main value
    /// Range in (-inf; +inf)
    pub main: f64,

    /// signal line value
    /// Range in (-inf; +inf)
    pub signal: f64,
}

/// Configuration for the Klinger Volume Oscillator (KVO) indicator.
/// Klinger Volume Oscillator: This indicator directly combines both price and volume data to assess buying and selling pressure.
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct KVOConfig {
    /// Fast moving average type.
    ///
    /// Default is EMA(34).
    ///
    /// Period range in [2; PeriodType::MAX).
    pub ma1: u8,

    ///Slow moving average type.
    ///
    ///Default is EMA(55).
    ///
    ///Period range in [2; PeriodType::MAX).
    pub ma2: u8,

    ///Signal line moving average type.
    ///
    ///Default is EMA(13).
    ///
    ///Period range in [2; PeriodType::MAX).
    pub signal: u8,
}

impl Default for KVOConfig {
    fn default() -> Self {
        Self {
            ma1: 34,
            ma2: 55,
            signal: 13,
        }
    }
}
